import { ref } from 'vue'
import { adapter, request } from '@/request'
import { accountMigrationByGet } from '@/core/api/promotion'
import type { RequestWrapper } from '@/core/interfaces/common'

interface Params {
  campaignId: number
}

export default function migrateAccount() {
  const service = adapter<RequestWrapper<any>>(request)
  const loading = ref(false)

  const fetch = (params: Params) => {
    const { url, method } = accountMigrationByGet()
    loading.value = true

    return service({
      config: {
        url,
        method,
        params
      },
      done: () => {
        loading.value = false
      }
    })
  }

  return [undefined, fetch, loading] as const
}
